
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 5029
 * @Author : WangRuoyu 
 * @Date : 2023/5/31 10:50
 */

#include "iostream"

using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    int nums[n];
    for (int i = 0; i < n; ++i) {
        scanf("%d", &nums[i]);
    }
    int res = 0;
    for (int i = 1; i < n - 1; ++i) {
        if (nums[i] > nums[i + 1] && nums[i] > nums[i - 1]) {
            res++;
        } else if (nums[i] < nums[i + 1] && nums[i] < nums[i - 1]) {
            res++;
        }
    }
    printf("%d", res);
    return 0;
}